<code>
<?
include('../db/koneksi.php');
$nm_tbl=$_POST['nm_tbl'];
$result = mysql_query("SHOW COLUMNS FROM $nm_tbl");
$resultx = mysql_query("SHOW COLUMNS FROM $nm_tbl");
$judul_atas=split('_',strtolower($nm_tbl));
$jum_atas=count($judul_atas);
$title='Form Input';
?>
&lt;?php
include '../db/koneksi.php';<br>
$page = isset($_POST['page']) ? $_POST['page'] : 1;<br>
$rp = isset($_POST['rp']) ? $_POST['rp'] : 10;<br>
$sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'name';<br>
$sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';<br>
$query = isset($_POST['query']) ? $_POST['query'] : false;<br>
$qtype = isset($_POST['qtype']) ? $_POST['qtype'] : false;<br>

/* -- To use the SQL, remove this block*/<br>
$usingSQL = true;<br>
function runSQL($rsql) {<br>

	

	$active_group = 'default';<br>

	$base_url = "http://".$_SERVER['HTTP_HOST'];<br>
	$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);<br>

	
	$result = mysql_query($rsql) or die ($rsql);<br>
	
	return $result;<br>
	mysql_close($connect);<br>
}<br>

function countRec($fname,$tname) {<br>
	$sql = "SELECT count($fname) FROM $tname ";<br>
	$result = runSQL($sql);<br>
	while ($row = mysql_fetch_array($result)) {<br>
		return $row[0];<br>
	}<br>
}<br>

$sort = "ORDER BY $sortname $sortorder";<br>
$start = (($page-1) * $rp);<br>

$limit = "LIMIT $start, $rp";<br>

$where = "WHERE status_delete <>1";<br>
if ($query) $where = " WHERE $qtype LIKE '%".mysql_real_escape_string($query)."%' AND status_delete <> 1";<br>

$sql = "select * FROM <?=$nm_tbl?> $where $sort $limit";<br>
$result = runSQL($sql);<br>
$resultx = runSQL($sql);<br>

$total = countRec("*","<?=$nm_tbl?> $where");<br>
//$rows=mysql_fetch_array($result);<br>
$valu=mysql_fetch_assoc($resultx);<br>
$field=array_keys($valu);<br>
//print_r($field);<br>
//die;<br>
$data_entry=array();<br>
while($val=mysql_fetch_array($result))<br>
{<br>
	$entry=array();<br>
	$k=0;<br>
	
	foreach($field as $valus )<br>
	{<br>
	$datas=$field[$k];<br>
	$isi=$val [$datas];<br>
	$datax=array($datas=>$isi);<br>
	$entry[$datas]=$isi;<br>
	$k++;<br>
	
	}<br>
	$data_entry[]=$entry;<br>
	

	
	
	
	
}<br>

if(!isset($usingSQL)){<br>
	include dirname(__FILE__).'/countryArray.inc.php';<br>
	if($qtype && $query){<br>
		$query = strtolower(trim($query));<br>
		foreach($rows AS $key => $row){<br>
			if(strpos(strtolower($row[$qtype]),$query) === false){<br>
				unset($rows[$key]);<br>
			}<br>
		}<br>
	}<br>
	//Make PHP handle the sorting<br>
	$sortArray = array();<br>
	foreach($rows AS $key => $row){<br>
		$sortArray[$key] = $row[$sortname];<br>
	}<br>
	$sortMethod = SORT_ASC;<br>
	if($sortorder == 'desc'){<br>
		$sortMethod = SORT_DESC;<br>
	}<br>
	array_multisort($sortArray, $sortMethod, $rows);<br>
	$total = count($rows);<br>
	$rows = array_slice($rows,($page-1)*$rp,$rp);<br>
}<br>
<?
	$l=1;
	if (mysql_num_rows($result) > 0) {

    while ($row = mysql_fetch_assoc($result)) {
	$index[$l]=strtolower($row['Field']);
	$l++;
	}
	}
	?>
header("Content-type: application/json");<br>
$jsonData = array('page'=>$page,'total'=>$total,'rows'=>array());<br>
//include dirname(__FILE__).'/countryArray.inc.php';<br>
foreach($data_entry as $row){<br>
//print_r($row);<br>
	//If cell's elements have named keys, they must match column names<br>
	//Only cell's with named keys and matching columns are order independent.<br>
	$entry = array('id'=>$row['<?=$index[1]?>'],<br>
		'cell'=>array(<br>
	
		'edit'=>'&lt;img src="../image/ico_actedit.png" style="cursor:pointer;" onclick="openPop('."'edit_<?=$nm_tbl?>.php'".','."'".$row['<?=$index[1]?>']."'".')" &gt;',<br>
'delete'=>' &lt;img src="../image/ico_acthapus.png" style="cursor:pointer;" onclick="hapus_data('."'".$row['<?=$index[1]?>']."'".')" &gt;',<br>
		
<?
for($a=0;$a<$jum_atas;$a++){
$title=$title.' '.ucwords($judul_atas[$a]);
}

?>
<hr>

<?
//$arrNama=split(",",$nama);
//$arrLabel=split(",",$label);
//$jumlah_kolom = count($arrNama);
$j=1;
if (mysql_num_rows($resultx) > 0) {

    while ($rowx = mysql_fetch_assoc($resultx)) {
	
	$yap=split('_',strtolower($row['Field']));
	$jenis=$row['Type'];
	$jum=count($yap);
	$judul=null;
	for($i=0;$i<$jum;$i++){
	$judul=$judul.' '.ucwords($yap[$i]);
	}
	
	?>
	
		'<?=strtolower($rowx['Field']);?>'=>$row['<?=strtolower($rowx['Field']);?>'],<br>
	<? 
	?>
	
  <? 
 
 }

}
//echo '&lt;/tr&gt;<br>';



?>
		),<br>
	);<br>
	$jsonData['rows'][] = $entry;<br>
}<br>

echo json_encode($jsonData);<br>

?&gt;
</code>
